#ifndef ROMFS2_H
#define ROMFS2_H

#include <QString>
#include <stdint.h>

#define ROMFS2_MAGIC    0x32534652

#define ROMFS2_ITEM_FILE    1
#define ROMFS2_ITEM_DIR      2

class romfs2
{
public:
    romfs2();
    ~romfs2();

public:
    struct romfs2_dirent
    {
        uint32_t type;
        uint32_t size;
        uint32_t data;
        uint32_t pos;
        char name[16];
    };

    struct romfs2_head
    {
        uint32_t magic;
        uint32_t volume;

        struct romfs2_dirent root;
    };

public:
    bool mkimg(QString &path);

private:
    struct romfs2_item
    {
        struct romfs2_dirent dirent;
        QByteArray data;
    };

    typedef QList<struct romfs2_item> rilist_t;

private:
    bool readfile(QString &name, QByteArray &buf);
    bool writefile(QString &name, QByteArray &buf);
    bool isdir(QString &name);
    void mklist(QString &name, rilist_t &list);
    bool do_mkimg(QString path, rilist_t &list);

public:
    QString errstr;
};

#endif // ROMFS2_H
